package xyz.bali16.module.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.bali16.module.blog.entity.ArticleTag;
import xyz.bali16.module.blog.mapper.ArticleTagMapper;
import xyz.bali16.module.blog.service.ArticleTagService;

import java.util.List;

/**
 * @author bali2 on 27/10/2021.
 * @version 1.0
 */
@Service("ArticleTag")
public class ArticleTagServiceImpl extends ServiceImpl<ArticleTagMapper, ArticleTag> implements ArticleTagService {
    @Autowired
    private ArticleTagMapper articleTagMapper;
    @Override
    public void addArticleTag(Long articleId, List<Long> tagIdsList) {
        this.remove(new QueryWrapper<ArticleTag>().eq("id", articleId));
        if(CollectionUtils.isEmpty(tagIdsList)){
            return;
        }
        articleTagMapper.delete(Wrappers.<ArticleTag>lambdaQuery().eq(ArticleTag::getArticleId,articleId));
        for(Long tagId : tagIdsList){
            ArticleTag articleTag = new ArticleTag();
            articleTag.setArticleId(articleId); 
            articleTag.setTagId(tagId);
            articleTagMapper.insert(articleTag);
        }
    }
    @Override
    public List<Long> queryArticleIdList(Long tagId) {
        return null;
    }
    @Override
    public List<Long> queryTagIdList(Long ArticleId) {
        return baseMapper.queryTagIdList(ArticleId);
    }
    @Override
    public Long countById(Long tagId) {
        return this.articleTagMapper.countByIds(tagId);
    }
//
//    @Override
//    public int deleteBatchByIds(Long[] tagIds) {
//        return baseMapper.deleteBatchByTagId(tagIds);
//    }

//    @Override
//    public PageUtils queryArticlePage(Integer current, Integer size) {
//        return null;
//    }


}
